export class itemInfo{
  constructor(itemInfo,columns){
    this.title = itemInfo.title;    //title
    this.price = itemInfo.price;   //11~84  
    this.oldPrice = itemInfo.oldPrice;   //打折前金额  string
    this.discountDesc = itemInfo.discountDesc;  //string 折扣
    this.columns = columns;  //array
  }
}

export class shopInfo{
  constructor(shopInfo){
    this.shopLogo = shopInfo.shopLogo;   //src
    this.shopUrl = shopInfo.shopUrl;   //url
    this.shopName = shopInfo.name;    //string
    this.cSells = shopInfo.cSells;   //number
    this.cGoods = shopInfo.cGoods;  //number
    this.score = shopInfo.score;   //array  产品描述
  }
}

export class detailInfo{
  constructor(detailInfo,itemParams){
    this.desc = detailInfo.desc;  //string
    this.key = detailInfo.detailImage[0].key; //string
    this.detailImage = detailInfo.detailImage[0].list;   //array
    this.rule = itemParams.rule;  //object  尺码等信息
    this.paramsInfo = itemParams.info;  //object  参数等说明
  }
}

export class detailComment{
  constructor(list){
    this.user = list.user;
      this.content = list.content;
      this.time = list.created;
      this.style = list.style;
  }
}

function padLeftZero(str) {
  return ("00" + str).substr(str.length);
}

export function formatDate(date, fmt) {
  if (/(y+)/.test(fmt)) {
    fmt = fmt.replace(RegExp.$1, (date.getFullYear()+50 + "").substr(4 - RegExp.$1.length));
  }

  let o = {
    "M+": date.getMonth() + 1,
    "d+": date.getDate(),
    "h+": date.getHours(),
    "m+": date.getMinutes(),
    "s+": date.getSeconds()
  };

  for (let k in o) {
    if (new RegExp(`(${k})`).test(fmt)) {
      let str = o[k] + "";
      fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : padLeftZero(str));
    }
  }

  return fmt;
}